package Thread;

//单例
class Singleton{
    private static Singleton instance = new Singleton();

    public static  Singleton getInstance(){   //后面需要获取这个类的实例就可以直接调用这个方法,而不是重新 new 一个
        return instance;
    }

    private Singleton(){    //单例模式核心操作:通过添加私有构造方法

    }
}

public class Demo27 {
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1 == s2); //true

//        Thread.Singleton s3 = new Thread.Singleton();
    }

}
